package com.ymeng;

import android.app.Activity;
import android.content.Context;

import com.umeng.socialize.bean.CallbackConfig;
import com.umeng.socialize.bean.RequestType;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.common.SocializeConstants;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.SinaShareContent;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.EmailHandler;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.RenrenSsoHandler;
import com.umeng.socialize.sso.SinaSsoHandler;
import com.umeng.socialize.sso.SmsHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;

/**
 * Created by wk on 15/1/27.
 */
public class UmentUtils {
    public static void init(String appKey) {
        SocializeConstants.APPKEY = appKey;
        //添加短信平台
        SmsHandler smsHandler = new SmsHandler();
        smsHandler.addToSocialSDK();
        //添加邮件平台
        EmailHandler emailHandler = new EmailHandler();
        emailHandler.addToSocialSDK();
    }

    public static void configRenRen(Activity activity, String id, String key, String secret) {
        final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share", RequestType.SOCIAL);
        RenrenSsoHandler renrenSsoHandler = new RenrenSsoHandler(activity, id, key, key);
        mController.getConfig().setSsoHandler(renrenSsoHandler);
    }

    public static void configWeiXin(Activity activity, String appId, String appSecret) {

// 添加微信朋友圈
        UMWXHandler wxCircleHandler = new UMWXHandler(activity, appId, appSecret);
        wxCircleHandler.setToCircle(true);
        wxCircleHandler.addToSocialSDK();
    }

    public static void configSina() {
        final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");
        mController.getConfig().setSsoHandler(new SinaSsoHandler());
    }

    public static void configQQZone(Activity activity, String id, String key) {
        QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(activity, id, key);
        qZoneSsoHandler.addToSocialSDK();
    }

    public static void configQQ(Activity activity, String id, String key) {
        UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(activity, id, key);
        qqSsoHandler.addToSocialSDK();
    }

    public static void open(String content, String url, UMImage umImage, Activity activity,SocializeListeners.SnsPostListener snsPostListener) {
        open(null, content, url, umImage, activity, snsPostListener);
    }
    public static void unRegisterListener(CallbackConfig.ICallbackListener iCallbackListener){
        final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");
        mController.getConfig().unregisterListener(iCallbackListener);

    }
    public static void open(String title, String content, String url, UMImage umImage, Activity activity, SocializeListeners.SnsPostListener snsPostListener) {
        final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");
        if (snsPostListener != null)
            mController.getConfig().registerListener(snsPostListener);


        WeiXinShareContent weiXinShareContent = new WeiXinShareContent();
        QQShareContent qqShareContent = new QQShareContent();
        CircleShareContent circleShareContent = new CircleShareContent();
        SinaShareContent sinaShareContent = new SinaShareContent();
        qqShareContent.setTargetUrl(url);
        qqShareContent.setShareImage(umImage);
        qqShareContent.setShareContent(content);
        qqShareContent.setTitle(title);



        circleShareContent.setTargetUrl(url);
        circleShareContent.setShareImage(umImage);
        circleShareContent.setShareContent(content);
        circleShareContent.setTitle(title);

        sinaShareContent.setTargetUrl(url);
        sinaShareContent.setShareImage(umImage);
        sinaShareContent.setShareContent(content);
        sinaShareContent.setTitle(title);


        weiXinShareContent.setTargetUrl(url);
        weiXinShareContent.setShareImage(umImage);
        weiXinShareContent.setShareContent(content);
        weiXinShareContent.setTitle(title);


        mController.setShareMedia(qqShareContent);
        mController.setShareMedia(circleShareContent);
        mController.setShareMedia(sinaShareContent);
        mController.setShareMedia(weiXinShareContent);
        mController.openShare(activity, false);

    }


}
